/**
 * @file rank/popularize/luogu1802/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/7 18:10:48
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010;
ll dp[N];
int n, x;
int main() {
  // High rating and good luck!
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    int win, lose, use;
    cin >> lose >> win >> use;
    for (int j = x; j - use >= 0; --j)
      dp[j] = max(dp[j] + lose, dp[j - use] + win);
    for (int j = use - 1; j >= 0; --j) dp[j] = dp[j] + lose;
  }
  cout << 5LL * dp[x] << endl;
  return 0;
}
